<?php
class TFunction {
	const CRYPTKEY = 'zr_e65$^vg41^948e*586"';

	/**
	 * Définis si la chaine passée en parametre est un mail ou non
	 */
	public static function isMail($mail){
		$return =false;
		if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
			$return =true;
		}
		return $return;
	}

	public static function crypt($string,$key=Functions::CRYPTKEY){
		$key = sha1($key);
		$return = '';
		for ($i = 0; $i<strlen($string); $i++) {
			$kc = substr($key, ($i%strlen($key)) - 1, 1);
			$return .= chr(ord($string{$i})+ord($kc));
		}
		return base64_encode($return);
	}

	public static function decrypt($string,$key=Functions::CRYPTKEY){
		$key = sha1($key);
		$return = '';
		$string = base64_decode($string);
		for ($i = 0; $i<strlen($string); $i++) {
			$kc = substr($key, ($i%strlen($key)) - 1, 1);
			$return .= chr(ord($string{$i})-ord($kc));
		}
		return $return;
	}
}
?>
